import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLEventListener;

/**
 * Created by WheelChen on 2017/5/19.
 */
public class TriangleRotation implements GLEventListener{
    private float rtri;  //for angle of rotation

    @Override
    public void init(GLAutoDrawable glAutoDrawable) {

    }

    @Override
    public void dispose(GLAutoDrawable glAutoDrawable) {

    }

    @Override
    public void display(GLAutoDrawable drawable) {
        final GL2 gl = drawable.getGL().getGL2();
        gl.glClear (GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT );
        // Clear The Screen And The Depth Buffer 清除屏幕和深度缓存

        gl.glLoadIdentity();                  // Reset The View
        gl.glRotatef( rtri, 0.0f, 1.0f, 0.0f );//triangle rotation

        gl.glBegin( GL2.GL_TRIANGLES );         // Drawing Using Triangles

        gl.glColor3f( 1.0f, 0.0f, 0.0f );           //Red
        gl.glVertex3f( 0.5f,0.7f,0.0f );            // Top

        gl.glColor3f( 0.0f,1.0f,0.0f );             //blue
        gl.glVertex3f( -0.2f,-0.50f,0.0f );         // Bottom Left

        gl.glColor3f( 0.0f,0.0f,1.0f );             //green
        gl.glVertex3f( 0.5f,-0.5f,0.0f );           // Bottom Right

        gl.glEnd();
        gl.glFlush();
        rtri +=1f;  //assigning the angle
    }

    @Override
    public void reshape(GLAutoDrawable glAutoDrawable, int i, int i1, int i2, int i3) {

    }
}
